package com.tenglong.teacher.ui.publish.text;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;

import com.tenglong.teacher.ui.publish.SelectType;

import java.io.Serializable;

import cn.hzw.doodle.DoodleBitmap;
import cn.hzw.doodle.DoodleText;
import cn.hzw.doodle.core.IDoodle;
import cn.hzw.doodle.core.IDoodleColor;
import cn.hzw.doodle.core.IDoodleItem;

/**
 * @author hdx on 2019/3/29.
 */
public class MyDoodleText extends DoodleText implements Serializable {
    private SelectType selectType;
    private TextPaint mTextPaint;
    private TextPaint myTextPaint;
    private float mX;
    private float mY;
    private StaticLayout myStaticLayout;
    private IDoodleItem errorBitmap;

    public MyDoodleText(IDoodle doodle, String text, float size, IDoodleColor color, float x, float y, SelectType selectType) {
        super(doodle, text, size, color, x, y);
        mX = x;
        mY = y;
        this.selectType = selectType;
    }

    public SelectType getSelectType() {
        return selectType;
    }

    public IDoodleItem getErrorBitmap() {
        return errorBitmap;
    }

    public void setErrorBitmap(IDoodleItem errorBitmap) {
        this.errorBitmap = errorBitmap;
    }

    @Override
    public void resetBounds(Rect rect) {
        super.resetBounds(rect);
//        String text = getText();
//        if (TextUtils.isEmpty(text)) {
//            return;
//        }
//        myTextPaint = new TextPaint();
//        myTextPaint.setAntiAlias(true);
//        myTextPaint.setTextSize(getSize());
//        myTextPaint.setColor(0xFF000000);
//        int width = 200;
//        Layout.Alignment alignment = Layout.Alignment.ALIGN_NORMAL;
//        float spacingMultiplier = 1;
//        float spacingAddition = 0;
//        boolean includePadding = false;
//        myStaticLayout = new StaticLayout(text, myTextPaint, width, alignment, spacingMultiplier, spacingAddition, includePadding);
//        float height = myStaticLayout.getHeight();
//        rect.left = (int) mX;
//        rect.top = (int) mY;
//        rect.bottom = (int) (mY+height);
//        rect.right = (int) (mX+width);
//        rect.offset(0, rect.height());
    }

    @Override
    public void doDraw(Canvas canvas) {
        super.doDraw(canvas);
//        getColor().config(this, myTextPaint);
//        myTextPaint.setTextSize(getSize());
//        myTextPaint.setStyle(Paint.Style.FILL);
//        canvas.save();
//        canvas.translate(0, getBounds().height() / getScale());
//        myStaticLayout.draw(canvas);
//        canvas.restore();
    }

    public void setSelectType(SelectType selectType) {
        this.selectType = selectType;
    }
}
